/**
 * 检查两个字符串各位是否不同，能一次交换，说明只有两个位不同
 * 记记不同的位数，检查交换后的字符串是否相等
 * @param {string} s1
 * @param {string} s2
 * @return {boolean}
 */
export var areAlmostEqual = function (s1, s2) {
  if (s1 === s2) return true
  if (s1.length !== s2.length) return false
  let diff = []
  for (let i = 0; i < s1.length; i++) {
    if (s1[i] !== s2[i]) diff.push(i)
    if (diff.length > 2) return false
  }
  if (diff.length === 2) {
    return s1[diff[0]] === s2[diff[1]] && s1[diff[1]] === s2[diff[0]]
  }
  return diff.length === 0
}
